package cate.common.table.activity.blessing.base;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
@EExcelRowClass(note = "食灵赐福 基础 Row")
public class BlessingBaseRow extends ERow {
    @EExcelNoteField(fieldName = "配置ID")
    public int configId;
    @EExcelNoteField(fieldName = "总奖券数")
    public int ticketCount;
    @EExcelNoteField(fieldName = "基础空位数")
    public int baseRewardCount;
    @EExcelNoteField(fieldName = "最大空位数")
    public int maxRewardCount;
    @EExcelNoteField(fieldName = "空位增长基数")
    public String rewardCountAddStr;
    @EExcelNoteField(fieldName = "终极大奖")
    public String rewardStr;
    @EExcelNoteField(fieldName = "邮件ID")
    public int mailId;
    @EExcelNoteField(fieldName = "提前结算小时数")
    public int settleHour;
    @EExcelNoteField(fieldName = "跑马灯")
    public int lampId;

    @NoteField("空位增长基数")
    public int rewardCountAddBase;
    @NoteField("空位增长数量")
    public int rewardCountAddNum;
    @NoteField("最大空位增长数")
    public int rewardCountAddMax;

    @Override
    public void decode() {
        super.decode();
        if (StringUtils.isNotBlank(rewardCountAddStr)) {
            try {
                String[] splits = rewardCountAddStr.split("\\|");
                rewardCountAddBase = Integer.parseInt(splits[0]);
                rewardCountAddNum = Integer.parseInt(splits[1]);
            } catch (Exception e) {
                log.error("[BlessingBaseRow] ID={} 解析 [空位增长基数] 报错! ", id, e);
            }
        }
        if (rewardCountAddBase <= 0) {
            log.error("[BlessingBaseRow] ID={} 解析 [空位增长基数] 基数={} 错误! ", id, rewardCountAddBase);
            rewardCountAddBase = 1;
        }
        if (rewardCountAddNum <= 0) {
            log.error("[BlessingBaseRow] ID={} 解析 [空位增长基数] 增量={} 错误! ", id, rewardCountAddNum);
            rewardCountAddNum = 1;
        }
        rewardCountAddMax = maxRewardCount - baseRewardCount;
        if (rewardCountAddMax < 0) {
            log.error("[BlessingBaseRow] ID={} 解析 [最大空位数] 小于 [基础空位数]", id);
            rewardCountAddMax = 0;
        }
    }
}
